﻿namespace AR
{
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Navigation;
    using AR.Views;
    using System.Linq;
    using AR.ViewModels;
    using AR.Entities;
    using AR.CustomEntities;

    /// <summary>
    /// Home page for the application.
    /// </summary>
    public partial class ListeCandidats : Page
    {
        /// <summary>
        /// Creates a new <see cref="Home"/> instance.
        /// </summary>
        public ListeCandidats()
        {
            InitializeComponent();
            this.Title = ApplicationStrings.HomePageTitle;
            this.DataContext = new ListeCandidatViewModel();
        }

        /// <summary>
        /// Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }


        private void _grid_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            IEnumerable<UIElement> elementsUnderMouse =
                VisualTreeHelper
                    .FindElementsInHostCoordinates(e.GetPosition(null), this);
            DataGridRow row =
                elementsUnderMouse
                    .Where(uie => uie is DataGridRow)
                    .Cast<DataGridRow>()
                    .FirstOrDefault();
            if (row != null)
            {
                CandidatGrid.SelectedItem = row.DataContext;
                ((this.DataContext) as ListeCandidatViewModel).SelectedCandidat = (row.DataContext as CustomCandidatEntretienEntity).candidat;
                ((this.DataContext) as ListeCandidatViewModel).VisibilityContextMenu = Visibility.Visible;
            }
            else 
            {
                   
                        ((this.DataContext) as ListeCandidatViewModel).VisibilityContextMenu = Visibility.Collapsed;
            }
        }
     
    }
}